﻿using System;
using System.Linq;
using System.Text;
using Sharp.Platform.Other;

namespace Sharp.WebBooter
{
    /// <summary>
    /// 工具栏代码具体实现
    /// </summary>
    public class BSToolButtons : Sharp.Platform.IToolButton
    {

        public string DetailsButton(ToolButtonInfo config)
        {
            return
                  "@Html.Bootstrap().LinkButton(\"浏览\", ToolBarIco.Details).Click(\"window.app.showEditWindow('dataList','\" + @Url.Action(\"Details\") + \"',this)\").Attribute(\"data-toggle\", \"ajaxModal\").Route(Url.Action(\"Details\"))";
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <returns></returns>
        public string CreateButton(ToolButtonInfo config)
        {
            return
                "@Html.Bootstrap().LinkButton(\"添加\", ToolBarIco.Create).Href(Url.Action(\"Create\")).Attribute(\"data-toggle\", \"ajaxModal\").Route(Url.Action(\"Create\"))";
        }



        public string EditButton(ToolButtonInfo config)
        {
            return
                "@Html.Bootstrap().LinkButton(\"修改\", ToolBarIco.Edit).Click(\"window.app.showEditWindow('dataList','\" + @Url.Action(\"Edit\") + \"',this)\").Attribute(\"data-toggle\", \"ajaxModal\").Route(Url.Action(\"Edit\"))";
        }

        public string DeleteButton(ToolButtonInfo config)
        {
            return
                "@Html.Bootstrap().LinkButton(\"删除\", ToolBarIco.Delete).Click(\"window.app.deleteItem('dataList','\" + @Url.Action(\"Delete\") + \"')\").Route(Url.Action(\"Delete\"))";
        }
        public string RefreshButton(ToolButtonInfo config)
        {
            return
                "@Html.Bootstrap().LinkButton(\"刷新\", ToolBarIco.Refresh).Click(\"window.app.search();\")";
        }
        /// <summary>
        /// 自定义按钮
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public string CustomButton(ToolButtonInfo config)
        {
            StringBuilder sb = new StringBuilder("@Html.Bootstrap()");
            sb.AppendFormat(".LinkButton(\"{0}\"", config.Title);
            if (!config.Icon.IsNullOrEmpty())
            {
                sb.AppendFormat(",{0}", config.Icon);
            }
            else
            {
                sb.Append(",ToolBarIco.Refresh");
            }
            sb.Append(")");
            if (!config.OnClientClick.IsNullOrEmpty())
            {
                sb.AppendFormat(".Click(\"{0}\")", config.OnClientClick);
            }

            //if (config.Direct != null)
            //{
            //    sb.AppendFormat(".DirectClickAction(\"{0}\", \"{1}\")", config.Direct.ActionName, config.Direct.ControllerName);
            //}
            //if (config.Parameters != null && config.Parameters.Any())
            //{
            //    sb.AppendLine(".DirectEvents(de =>");
            //    sb.AppendLine("{");
            //    foreach (var p in config.Parameters)
            //    {

                     
            //    }
            //    sb.AppendLine("})");
            //}

            return sb.ToString();
        }
    }
}